package com.fenshi.manager.activity.user;

import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.fenshi.manager.R;
import com.fenshi.manager.activity.login.LoginActivity;
import com.fenshi.manager.activity.message.MessageActivity;
import com.fenshi.until.CookicUntil;
import com.quickdv.activity.BaseActivity;
import com.umeng.update.UmengUpdateAgent;
import com.umeng.update.UmengUpdateListener;
import com.umeng.update.UpdateResponse;


public class UserCenter extends BaseActivity implements View.OnClickListener {

    LinearLayout setting, message, cancel, version,location;
    TextView user;

    @Override
    public int getLayoutID() {
        return R.layout.activity_user_center;
    }

    @Override
    public void initView() {
        user = findView(R.id.user_code);
//        setting = findView(R.id.user_setting);
        message = findView(R.id.user_messages);
        cancel =findView(R.id.user_canceling);
        version = findView(R.id.check_version);

        TextView version_value = findView(R.id.version_value);
        location = findView(R.id.save_location);
//        setting.setOnClickListener(this);
        message.setOnClickListener(this);
        cancel.setOnClickListener(this);
        version.setOnClickListener(this);
        location.setOnClickListener(this);

        user.setText(CookicUntil.getUser().getTel());


        try {
            PackageManager manager = this.getPackageManager();
            PackageInfo info = manager.getPackageInfo(this.getPackageName(), 0);
            String version = info.versionName;
            version_value.setText("版本:"+version + "");

        }
        catch (Exception e){

        }
    }

    @Override
    public void initActionbar() {

    }

    @Override
    public void initData(){
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
//            case R.id.user_setting:
//                Intent intent3 = new Intent(UserCenter.this, EditPwdActivity.class);
//                startActivity(intent3);
//                break;
            case R.id.user_messages:
                Intent intent1 = new Intent(UserCenter.this, MessageActivity.class);
                startActivity(intent1);
                break;
            case R.id.user_canceling:
                Intent intent = new Intent(UserCenter.this, LoginActivity.class);
                startActivity(intent);
                Intent intent2 = getIntent();
                setResult(200,intent2);
                finish();
                break;
            case R.id.check_version:
                UmengUpdateAgent.update(this);
                UmengUpdateAgent.setUpdateOnlyWifi(false);
                UmengUpdateAgent.setUpdateListener(new UmengUpdateListener() {
                    @Override
                    public void onUpdateReturned(int i, UpdateResponse updateResponse) {
                        if (i == 0) {
                            Toast.makeText(UserCenter.this,"当前已是最新版本",Toast.LENGTH_LONG).show();
                        }
                    }
                });
                break;
            case R.id.save_location:
                Intent intent3 = new Intent(this,LocationActivity.class);
                startActivity(intent3);
                break;
        }
    }
}
